#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
using namespace std;
using ull = unsigned long long;
#define int long long
//using i128 = __int128_t;
inline int inc(int x, int v, int mod) { x += v;return x >= mod ? x - mod : x; }//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 2e3 + 10, M = 1e5 + 10;

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

void solve()
{
    int n,h,m;
    cin >> n >> h >> m;
    set<pair<string,int>> sp;
    int ans1 = 0,ans2 = 0,ans3 = 0;
    string posmonth; 
    if(m < 10)
    {
        posmonth.push_back('0');
        posmonth.push_back(m + '0');
    }
    else posmonth = to_string(m);
    for(int i = 1; i <= n; i ++)
    {
        string userid;
        cin >> userid;
        string s1;
        cin >> s1;
        string s2;
        cin >> s2;
        string year = s1.substr(0,4);
        string month = s1.substr(5,2);
        if(year == to_string(h) && posmonth == month)
        {
            pair<string,int> tp;
            string time = s2.substr(0,2);
            if(time == "07" || time == "08" || time == "09" || time == "18" || time == "19" || time == "20") 
            {
                if(time == "20" || time == "09")
                {
                    string tt1 = s2.substr(3,2);
                    string tt2 = s2.substr(6,2);
                    if(tt1 != "00" || tt2 != "00") continue;
                }
                tp = {userid,1};
                if(sp.find(tp) == sp.end())
                {
                    sp.insert(tp);
                    ans1++;
                }
            }
            if(time == "11" || time == "12" || time == "13")
            {
                if(time == "13")
                {
                    string tt1 = s2.substr(3,2);
                    string tt2 = s2.substr(6,2);
                    if(tt1 != "00" || tt2 != "00") continue;
                }
                tp = {userid,2};
                if(sp.find(tp) == sp.end())
                {
                    sp.insert(tp);
                    ans2++;
                }
            }
            if(time == "22" || time == "23" || time == "00" || time == "01")
            {
                if(time == "01")
                {
                    string tt1 = s2.substr(3,2);
                    string tt2 = s2.substr(6,2);
                    if(tt1 != "00" || tt2 != "00") continue;
                }
                tp = {userid,3};
                if(sp.find(tp) == sp.end())
                {
                    sp.insert(tp);
                    ans3++;
                }
            }
        }
    }
    cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt;
    //cin >> tt;
    tt = 1;
    while (tt--)
    {
        solve();
    }
}